import { ref } from 'vue'
import PageModal from '@/components/page-modal'

type cbFn = (item?: any) => void

export function usePageModal(createCb: cbFn, editCb: cbFn) {
  const pageModalRef = ref<InstanceType<typeof PageModal>>()
  const defaultInfo = ref({})
  const handleCreateClick = () => {
    defaultInfo.value = {}
    console.log('createBtnClick')
    pageModalRef.value?.changeDialogVisible()
    createCb && createCb()
  }

  const handleEditClick = (item: any) => {
    defaultInfo.value = { ...item }
    console.log('editBtnClick')
    pageModalRef.value?.changeDialogVisible()
    editCb && editCb(item)
  }
  return [pageModalRef, defaultInfo, handleCreateClick, handleEditClick]
}
